﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Timers;
using System.Net.Sockets;
using VFDDriver.Properties;

namespace VFDDriver.XBMC
{
    public class XBMCData
    {
        #region Instance

        static XBMCData _instance;

        /// <summary>
        /// Instance of the XBMCData.
        /// </summary>
        public static XBMCData Instance
        {
            get
            {
                if (_instance == null)
                    _instance = new XBMCData();
                return _instance;
            }
        }

        #endregion

        UdpClient _udpClient;

        Timer timer;

        private XBMCData()
        {

        }

        public void Start()
        {
           

            timer = new Timer(500);
            timer.Elapsed += new ElapsedEventHandler(timer_Elapsed);
            timer.Start();
        }

        int count = 0;

        void timer_Elapsed(object sender, ElapsedEventArgs e)
        {
            Data.Instance.SetData(1, "abcdefghijklmnopqrstuvwxyz", VFDDriver.Alignment.Left);
            Data.Instance.SetData(2, "abcdefghizklmnopqrstuvwxyz", VFDDriver.Alignment.Right);

            //if (count < 5)
            //{
            //    Data.Instance.SetData(1, "TestTestTestTestTestTest", VFDDriver.Alignment.Left);
            //    Data.Instance.SetData(2, "${time}", VFDDriver.Alignment.Left);
            //}
            //else if (count < 10)
            //{
            //    Data.Instance.SetData(1, "TestTestTestTestTestTest", VFDDriver.Alignment.Right);
            //    Data.Instance.SetData(2, "${time}", VFDDriver.Alignment.Center);
            //}
            //else if (count < 15)
            //{
            //    Data.Instance.SetData(1, "TestTestTestTestTestTest", VFDDriver.Alignment.Right);
            //    Data.Instance.SetData(2, "${time}", VFDDriver.Alignment.Right);
            //}
            ////else if (count < 20)
            ////{
            ////    Data.Instance.SetData(1, "TestTestTestTestTestTest", VFDDriver.Alignment.Left);
            ////    Data.Instance.SetData(2, "${time}", VFDDriver.Alignment.Left);
            ////}
            //else
            //    count = 0;
            //count++;
        }

        public void Stop()
        {
            timer.Stop();
            timer.Elapsed -= new ElapsedEventHandler(timer_Elapsed);
            timer.Dispose();
            timer = null;
        }
    }
}
